package com.person.jc.web.test.certificate;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.kit.JsonKit;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.person.jc.common.Constants;
import com.person.jc.entity.TsUser;
import com.person.jc.service.base.device.BdDeviceRelationService;
import com.person.jc.service.service.BsOrderService;
import com.person.jc.service.test.certificate.MakeService;
import com.person.jc.service.test.certificate.SendService;
import com.person.jc.service.test.inspect.BsReconditionLogService;
import com.person.jc.utils.Servlets;
import com.person.jc.utils.SessionKit;
import org.apache.commons.lang.StringUtils;

import java.util.*;

/**
 * Created by ailk on 2017/9/23.
 */
public class SendController extends Controller {
    public void init(){
        setAttr("menuId", getPara("menuId"));
        render("main.jsp");
    }

    public void list(){
        Map<String, Object> map = Servlets.getParametersStartingWith(getRequest(), "p_");
        TsUser tsUser = (TsUser) SessionKit.get().getAttribute(Constants.LOGIN_USER);
        map.put("optUser", tsUser.getUserId());
//        map.put("orderType","3");
        map.put("flow", Constants.FLOW_WX_WXRW);
        List<Record> list = SendService.me.getList(map);
        setAttr("list", list);
        render("list.jsp");
    }

    public void showEdit(){
        String orderId=getPara("orderId");

        Record rc=SendService.me.findOrderById(orderId);

        setAttr("obj",rc);
        setAttr("orderId",orderId);
        render("edit.jsp");
    }

    @Before(Tx.class)
    public void saveSendInfo(){
        Map<String, Object> map = Servlets.getParametersStartingWith(getRequest(), "p_");
        int num=SendService.me.updateSendInfo(map);
        BsOrderService.me.updateOrderStatus(map.get("order_id").toString(), 2);
        //修改订单状态,进入开票节点
        BsOrderService.me.updateFlow(map.get("order_id").toString(),Constants.FLOW_JCWX_SQKP);

        renderText("success");
    }


}
